#include "app_buffer.h"
buffer_t *buffer;

void *my_read(void *arg)
{
    while (1)
    {
        char data[10];
        int real_len = app_buffer_read(buffer, data, 10);
        if (real_len > 0)
        {
            log_info("read: %.*s", real_len, data);
        }
    }
}

void *my_write(void *arg)
{

    while (1)
    {
        app_buffer_write(buffer, "a", 1);
        sleep(3);
    }
}

int main(int argc, char const *argv[])
{
    buffer = app_buffer_init(10);

    app_buffer_write(buffer, "hello", 5);

    char data[10];
    int real_len = app_buffer_read(buffer, data, 10);
    log_info("read: %.*s", real_len, data);

    real_len = app_buffer_read(buffer, data, 10);
    log_info("read: %.*s", real_len, data);

    pthread_t t1;
    pthread_t t2;
    pthread_create(&t1, NULL, my_read, NULL);
    pthread_create(&t2, NULL, my_write, NULL);

    pthread_join(t1, NULL);
    pthread_join(t2, NULL);

    return 0;
}
